/**************************提示：只允许修改开发区域，其他区域会被覆盖！********************************/
mod.definePage("extend/cp/bc/js/DailyLoanBill_Edit_Open001",function(waf){
    //@beginUseModule
    var bizCollBillBase = mod.useSync("cp/bc/js/bizCollBillBase");
    var bizCollBillEdit = mod.useSync("cp/bc/js/bizCollBillEdit");
    var promptExpenseType = mod.useSync("cp/bc/js/promptExpenseType");
    var DailyLoanBill_Edit_Open = mod.useSync("cp/bc/js/DailyLoanBill_Edit_Open");
    var promptSpecial_Project = mod.useSync("extend/custom/ct/js/promptSpecial_Project");
    //@endUseModule
    var _public = {},_private = {},me=_self;
    //@beginPublic
    waf.extend(_public,{
        //控件事件描述:
        costedDeptChange:function(event,value){
             return _private.costedDeptChange(event,value);
        }
	    ,
        //控件事件描述:
        borrowingTypeChange:function(event,ui){
             return _private.borrowingTypeChange(event,ui);
        }
	    ,
        //控件事件描述:
        projectChange:function(event,value){
             return _private.projectChange(event,value);
        }
	    ,
        //页面事件描述:控件隐藏/显示
        controlHandling:function(e){
             return _private.controlHandling(e);
        }
	    ,
        //页面事件描述:
        entriesControlChange:function(e){
             return _private.entriesControlChange(e);
        }
    });
    _self.subscribeEvent("fieldOnLoadEvent",_public.controlHandling,"after");
    _self.subscribeEvent("pageOnLoadEvent",_public.entriesControlChange,"after");
    //@endPublic
    //@beginTemplateFunctions

    //@endTemplateFunctions

    /**************************开发区域开始**********************************************/
    //@beginPrivate
    waf.extend(_private,{
      
		borrowingTypeChange:function(event,ui){
          var borrowingType=ui.current;
          if(borrowingType!='5'){
           waf("#contractNumber").wafText("option","disabled",false);
		   waf("#contractMoney").wafNumberField("option","disabled",false);
		    waf("#paid").wafNumberField("option","disabled",false);
          }else{
            waf("#contractNumber").wafText("option","disabled",true);
		    waf("#contractMoney").wafNumberField("option","disabled",true);
		    waf("#paid").wafNumberField("option","disabled",true);
          }
        }
    	,
		controlHandling:function(e){
         $("#entries").wafGrid("hideColumn","project",true);
          var cols = waf("#entries").wafGrid("getAllColumn");
					for (var i = 0; i < cols.length; i++) {	//遍历列
						var col = cols[i];

						if (col.id == "ext_gridCol0" ) {				
								//获取配置界面的自定义F7的url的值
						    	var url = col.editoptions.subTagJson.url;
						
								//如果是customF7开头（随便写，自定义的）
								if (url.indexOf("customF7") >= 0) {
									//修改列的编辑属性subWidgetName的值为customF7后面
									col.editoptions.subWidgetName = url.slice(url.indexOf('=') + 1);
								}
							}
					}

          
          var borrowingType= waf("#borrowingType").wafSelect("getValue");
           if(borrowingType!='5'){
           waf("#contractNumber").wafText("option","disabled",false);
		   waf("#contractMoney").wafNumberField("option","disabled",false);
		    waf("#paid").wafNumberField("option","disabled",false);
          }else{
            waf("#contractNumber").wafText("option","disabled",true);
		    waf("#contractMoney").wafNumberField("option","disabled",true);
		    waf("#paid").wafNumberField("option","disabled",true);
          }
          
           var costedDept=waf("#costedDept").wafPromptBox("getValue");
           waf("#entries").wafGrid('setCellEditorAllConfig', "project","filteritem","admin.id='"+costedDept.id+"'  or  admin.id = null","promptGrid",null); 
        }
    	,
		costedDeptChange:function(event,value){
          //是否清空费用类型
			var entryDom = waf("#entries");
			var rowIds = entryDom.wafGrid("getDataIDs");
		    var operationTypeIds = [];
		    for (var i = 0, il = rowIds.length; i < il; i++) {
				var rowId = rowIds[i];
				var operationTypeId = null;
	        	var rowId = rowIds[i];
	        	var expenseType = entryDom.wafGrid("getCell", rowId, "expenseType");
				if(expenseType != ""){
					operationTypeId = expenseType.operationType.id;
					operationTypeIds.push(operationTypeId);
				}
				//entryDom.wafGrid("setCell", rowIds[i], "expenseType", null);
				entryDom.wafGrid("setCell", rowId, "bgText", null);
			}
			operationTypeIds =  waf.toJSONString(operationTypeIds);
			bizCollBillEdit.costedDept_onchange(event, value, operationTypeIds, rowIds);
			// 清空分录-费用类型(不加在bizCollBillEdit里,防止出差借款单这种分录表格得分开处理.)
//			waf(".expenseType input[ctrlrole='promptBox']").wafPromptBox("setValue", null);
			// 清空费用类型,预算信息
			var entryDom = waf("#entries"),
				rowIds = entryDom.wafGrid("getDataIDs");
			for (var i = 0, il = rowIds.length; i < il; i++) {
				var rowId = rowIds[i];
				//entryDom.wafGrid("setCell", rowIds[i], "expenseType", null);
				entryDom.wafGrid("setCell", rowId, "bgText", null);
			}
			waf("#bgDataText").wafText("setValue", null);
			
	        //bizCollBillEdit.costedDept_onchange_for_bg(event, value);
			bizCollBillEdit.showBgData("costedDept", value.current, true, false);
          
            waf("#entries").wafGrid('setCellEditorAllConfig', "project","filteritem","admin.id='"+value.current.id+"'  or  admin.id = null","promptGrid",null);
        }
    
    	,
		projectChange:function(event,value){
          var curent = value.current;
          var editGridDom = waf("#entries");
          var rowid = editGridDom.wafGrid("getSelectedRow");
       	   editGridDom.wafGrid("setCell", rowid, "project",curent);
          
           bizCollBillEdit.entry_project_onchange_for_bg(null,curent);
				//改变超预算说明
				bizCollBillEdit.changeBudgetDescription(false);
        }
    	,
		entriesControlChange:function(e){
           var editGridDom = waf("#entries");
           var getDataIDs = editGridDom.wafGrid("getDataIDs");
            for(var i=0;i<getDataIDs.length;i++){
              var rowid=getDataIDs[i];
              var project = editGridDom.wafGrid("getCell", rowid, "project");
              editGridDom.wafGrid("setCell", rowid, "ext_gridCol0",project);
            }
        }
    });//@endPrivate
    /**************************开发区域结束**********************************************/
    return _public;
});
